'use strict'

const gulp = require('gulp')
const babel = require('gulp-babel')
// const stripDebug = require("gulp-strip-debug");
const clean = require('gulp-clean')
const time = new Date().toLocaleDateString().replaceAll('/', '-')

const inputDir = './html.js'
const outputDir = './' + time + '-newImg' + '-dist'
function js() {
  console.log('start js')
  return (
    gulp
      .src(inputDir)
      // .src(['./src/**/*.js', '!./src/**/*.min.js'])
      // .pipe(stripDebug()) // 去除所有console语句
      .pipe(
        babel({
          presets: ['@babel/env']
        })
      )
      .pipe(gulp.dest(outputDir))
  )
}
function minjs() {
  console.log('start minjs')
  return gulp.src(['./src/**/*.min.js']).pipe(gulp.dest(outputDir))
}
function css() {
  console.log('start css')
  return (
    gulp
      .src(['./src/**/*.+(scss|css)'])
      // .pipe(autoprefixer())
      // .pipe(sass().on("error", sass.logError))
      .pipe(gulp.dest(outputDir))
  )
}

function html() {
  console.log('start html')
  return gulp.src('./src/**/*.html').pipe(gulp.dest(outputDir))
}
function img() {
  console.log('start img')
  return gulp.src('./src/**/*.img').pipe(gulp.dest(outputDir))
}

function remove() {
  console.log('clean start')
  return gulp.src('./' + outputDir, { read: false, allowEmpty: true }).pipe(clean())
}

// 默认打包
gulp.task('default', gulp.series(remove, gulp.parallel(js)))
